package com.jt.controller;

import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.vo.EasyUITable;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jt.service.ItemService;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@RequestMapping("/item/")
public class ItemController {
	
	@Autowired
	private ItemService itemService;

	/**
	 *业务需求:商品信息的分页查询
	 * url地址
	 * 请求参数
	 * 返回值结果
	 *
	 */
	@RequestMapping("query")
	public EasyUITable query(Integer page,Integer rows){

		return itemService.findAll(page,rows);
	}

	/**
	 * 业务需求:完成商品入库操作,返回vo对象
	 * url:/item/save
	 * 参数:整个from表单
	 * 返回值:SysResult对象刘昱江
	 */
	@RequestMapping("save")
	public SysResult saveItem(Item item, ItemDesc itemDesc){
			itemService.saveItem(item,itemDesc);
			return SysResult.success();
	}

	@RequestMapping("delete")
	public SysResult deleteItem(Long ... ids){
			itemService.deleteItem(ids);
			return SysResult.success();
	}

	@RequestMapping("update")
	public SysResult updateItem(Item item,ItemDesc itemDesc){
		itemService.updateItem(item,itemDesc);
		return SysResult.success();
	}

	/*@RequestMapping("instock")
	public SysResult instockItem(Long ...ids){
		System.out.println(Arrays.toString(ids));
		itemService.instockItem(ids);
		return SysResult.success();
	}

	@RequestMapping("reshelf")
	public SysResult reshelfItem(Long ...ids){
		itemService.reshelfItem(ids);
		return SysResult.success();
	}*/

	@RequestMapping("updateStatus/{status}")
	public SysResult updateStatus(@PathVariable Integer status,Long ...ids){
		itemService.updateStatus(status,ids);
		return SysResult.success();
	}

	@RequestMapping("query/item/desc/{itemId}")
	public SysResult findItemDescById(@PathVariable Long itemId){
		ItemDesc itemDesc=itemService.findItemDescById(itemId);
		return SysResult.success(itemDesc);
	}
}
